package com.order.service;

import java.util.List;

import com.order.dao.BaseDao;
import com.order.entity.Detail;
import com.order.entity.Goods;
import com.order.entity.Order;

public class OrderService {
	/**
	 * 添加订单信息到数据库
	 * @param order 订购信息
	 * @param glist 商品列表
	 * @param amounts 商品数量
	 * @return 执行结果
	 */
	public int addOrder(Order order, List<Goods> glist, int[] amounts) {
		//one方进行级联操作
		for (int i = 0; i < glist.size(); i++) {
			Detail detail = new Detail();
			detail.setGoods(glist.get(i));
			detail.setOrder(order);
			detail.setAmount(amounts[i]);
			order.getDetails().add(detail);
		}
		return new BaseDao().Update(order, 1);
	}
	
	public Order findOrder(int id) {
		return (Order) new BaseDao().getObject(Order.class, id);
	}
}
